Skip to content

Fix CLI register path dedup and local timm model export (#2417, #2423) - #2478

Open
Zhussup wants to merge 1 commit into
huggingface:mainfrom
Zhussup:fix/cli-and-timm-export-issues
Open

Fix CLI register path dedup and local timm model export (#2417, #2423)#2478
Zhussup wants to merge 1 commit into
huggingface:mainfrom
Zhussup:fix/cli-and-timm-export-issues

Conversation

@Zhussup

@Zhussup Zhussup commented Aug 12, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes two issues addressable in the core optimum repository and updates the contributing guide to reflect the current split into subpackages.

#2417 — sub-commands fail on RHEL (lib64 → lib symlink)

load_optimum_namespace_cli_commands deduplicated submodule_search_locations with a plain set() over the raw strings. On systems where lib64 is a symlink to lib (e.g. RHEL), this returns two entries pointing to the same physical directory, so subpackage commands were registered twice and spurious __init__.py warnings were emitted.

Fix: deduplicate by the resolved physical path (Path.resolve()) and guard iterdir() with a try/except OSError.

#2423 — cannot export local timm models

The timm loading branch always passed hf_hub:{model_name_or_path} to timm.create_model. For a local directory, timm interprets the hf-hub/hf_hub source prefix as a Hub repo id and fails to download it. timm does not accept a bare local path — the local-dir: source prefix is required for local folders.

Fix: select the source prefix based on whether the argument is a local directory:

  • local directory → local-dir:{path}
  • otherwise → hf_hub:{path} (unchanged)

CONTRIBUTING.md

Added a "Where does my contribution belong?" section mapping features/backends to their subpackage repositories (optimum-onnx, optimum-intel, optimum-habana, optimum-neuron, optimum-amd, optimum-nvidia, optimum-quanto, optimum-furiosa, optimum-executorch), and clarifying that this repository holds the shared core (CLI, optimum/exporters/tasks.py, utils).

Tests

  • tests/cli/test_cli.py::TestCLI::test_load_namespace_cli_commands_dedup_symlink — regression test for Cannot run sub-commands on RHL because optimum mishandles the lib64 symlink to lib #2417 using an isolated temp directory plus a symlink duplicate and a namespace ModuleSpec.
  • tests/exporters/common/test_timm_loading.py — verifies the local-dir: prefix is used for a local path and hf_hub: is preserved for a Hub repo id (mocks timm.create_model, no network/weights).

Both pass with transformers 4.57.6 and transformers 5.15.0.

Notes from triage (no code change needed in this repo)

- Deduplicate optimum.commands.register search locations by the resolved
  physical path so symlinked lib64 -> lib directories on RHEL no longer
  register subcommands twice or emit spurious __init__.py warnings (huggingface#2417).
- Load local timm models with the `local-dir:` source prefix instead of
  `hf_hub:`, which timm rejects for local directory paths (huggingface#2423).
- Add a "Where does my contribution belong?" section to CONTRIBUTING.md
  mapping features to their subpackage repositories.
- Add regression tests for both fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant